package com.frontcamera;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MainActivity extends Activity {
  static   SharedPreferences preferences;
    SharedPreferences.Editor editor;
    public   EditText ed;
    public  static String et;
    Context context = MainActivity.this;
    SurfaceView surfaceView;
    CameraSurfaceHolder mCameraSurfaceHolder = new CameraSurfaceHolder();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    public void initView() {
        setContentView(R.layout.activity_main);
        surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);


        mCameraSurfaceHolder.setCameraSurfaceHolder(context, surfaceView);


        Button openDoorButton = (Button) findViewById(R.id.openDoorButton);
        preferences=getSharedPreferences("id",MODE_PRIVATE);
        editor=preferences.edit();
   ed= (EditText) findViewById(R.id.ed);

   ed.addTextChangedListener(new TextWatcher() {
       @Override
       public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {



       }

       @Override
       public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
           et=ed.getText().toString();

       }

       @Override
       public void afterTextChanged(Editable editable) {



       }
   });





       openDoorButton.setOnClickListener(OpenDoorListener.getInstance());

      //  OpenDoorListener.getInstance();
       // ApiFaceSample.getInstance().faceverify(SurfaceViewCallback.getInstacne().mCurrentFrame64);

        final Button RegisterDoorButton = (Button) findViewById(R.id.registerDoorButton);



        RegisterDoorButton.setOnClickListener(RegisterDoorButtonListener.getInstance());
//    RegisterDoorButton.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View view) {
//            Intent intent=new Intent(MainActivity.this,Main2Activity.class);
//            startActivity(intent);
//
//            AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
//            View view1 = View.inflate(MainActivity.this, R.layout.activity_alter_dialog_setview, null);
//            final EditText et = (EditText) view1.findViewById(R.id.ed);
//            Button bu = (Button) view1.findViewById(R.id.btn);
//            dialog
//                    .setTitle("Login")
//                    .setIcon(R.mipmap.ic_launcher)
//                    .setView(view1)
//                    .create();
//            final AlertDialog show = dialog.show();
//            bu.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    Toast.makeText(MainActivity.this, "电话" + et.getText().toString(), Toast.LENGTH_SHORT).show();
//                    show.dismiss();
//                }
//            });

//            RegisterDoorButtonListener.getInstance();
//
//
//        }
//    });





//        RegisterDoorButton.setOnClickListener(RegisterDoorButtonListener.getInstance(),  intent=new Intent(MainActivity.this,Main2Activity.class),startActivity(intent));
//

    }


    public  void s(){

        final Handler handler=new Handler();
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
                // TODO Auto-generated method stub

                AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
                View view1 = View.inflate(MainActivity.this, R.layout.activity_alter_dialog_setview, null);
                final EditText et = (EditText) view1.findViewById(R.id.ed);
                Button bu = (Button) view1.findViewById(R.id.btn);
                dialog
                        .setTitle("Login")
                        .setIcon(R.mipmap.ic_launcher)
                        .setView(view1)
                        .create();
                final AlertDialog show = dialog.show();
                bu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Toast.makeText(MainActivity.this, "电话" + et.getText().toString(), Toast.LENGTH_SHORT).show();
                        show.dismiss();
                    }
                });



                handler.postDelayed(this, 2000);
            }
        };

    }


}
